package com.baosight.sczx.zm.cn.service;
import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.zm.cn.domain.ZMCNCoalAccount;
import com.baosight.sczx.zm.cn.domain.ZMCNYdzhcyMain;
/**
 * 毛煤
 */
public class ServiceZMCN51 extends ServiceEPBase {
	/**
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化</p> 
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
//		outInfo.addBlock(StaticBlocks.getStauts4());
//		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cp.department", "orgCode", "orgName", false));
//		outInfo.set("fdCreatorId", UserSession.getUserId());//登录人的默认值
//		outInfo.set("fdCreator", UserSession.getInSessionProperty("UserCname"));
//		outInfo.set("fdCreateDepartmentId", UserSession.getInSessionProperty("orgCode"));//单位的默认值		
//		outInfo.set("fdCreateDepartment", UserSession.getInSessionProperty("orgName"));//单位的默认值
		return inInfo;
	}
	/**
	 * <p>Function: query</p>
	 * <p>Description: 查询</p> 
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		EiInfo outInfo = super.query(inInfo, "ZMCNCoalAccount.query", new ZMCNCoalAccount());
		outInfo.addBlock(StaticBlocks.getStauts4());
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cp.department", "orgCode", "orgName", false));
		outInfo.set("fdCreatorId", UserSession.getUserId());//登录人的默认值
		outInfo.set("fdCreator", UserSession.getInSessionProperty("UserCname"));
		outInfo.set("fdCreateDepartmentId", UserSession.getInSessionProperty("orgCode"));//单位的默认值		
		outInfo.set("fdCreateDepartment", UserSession.getInSessionProperty("orgName"));//单位的默认值
		return outInfo;
	}	
	
//	/**
//	 * <p>Function: insert</p>
//	 * <p>Description: 新增</p> 
//	 */
//	@Override	
//	public EiInfo insert(EiInfo inInfo) {
//		EiInfo outinfo = new EiInfo();
//		ZMCNCoalAccount _dom = new ZMCNCoalAccount();
//		EiBlock eiBlock = inInfo.getBlock("result");
//		eiBlock.setBlockMeta(_dom.eiMetadata);
//		int rowcount = eiBlock.getRowCount();
//
//		for (int i = 0; i < rowcount; i++) {
//			_dom.fromMap(eiBlock.getRow(i));
//			this.dao.insert("ZMCNCoalAccount.insert", _dom);
//		}
//		outinfo = this.query(inInfo);
//		outinfo.setStatus(1);
//		outinfo.setMsg("操作" + rowcount + "记录成功");
//		return outinfo;
//	}
	 
	/**
	 * <p>Function: update</p>
	 * <p>Description: 修改</p> 
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		ZMCNCoalAccount _dom = new ZMCNCoalAccount();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		for (int i = 0; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			this.dao.update("ZMCNCoalAccount.update", _dom);
		}
		outInfo = this.query(inInfo);
		outInfo.setStatus(1);
		outInfo.setMsg("操作" + rowcount + "记录成功");
		return outInfo;
	}	
//	/**
//	 * <p>Function: delete</p>
//	 * <p>Description: 删除</p> 
//	 */
//	@Override
//	public EiInfo delete(EiInfo inInfo) {
//		EiInfo outInfo = new EiInfo();
//		ZMCNCoalAccount _dom = new ZMCNCoalAccount();
//		EiBlock eiBlock = inInfo.getBlock("result");
//		eiBlock.setBlockMeta(_dom.eiMetadata);
//		int rowcount = eiBlock.getRowCount();
//		for (int i = 0; i < rowcount; i++) {
//			_dom.fromMap(eiBlock.getRow(i));
//			this.dao.delete("ZMCNCoalAccount.delete", _dom);
//		}
//		outInfo = this.query(inInfo);
//		outInfo.setStatus(1);
//		outInfo.setMsg("操作" + rowcount + "记录成功");
//		return outInfo;
//	}	 
	
	/**
	 * 上报
	 * <p>Function: report</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-6下午04:07:27 张志芳
	 * </p>
	 *
	 */
	public EiInfo report(EiInfo inInfo)
	{
		EiInfo out=new EiInfo(); 
		ZMCNCoalAccount _dom = new ZMCNCoalAccount();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			
			Map<String, String> params = new HashMap<String, String>();
			params.put("fdKeyId", _dom.getFdKeyId());

			this.dao.update("ZMCNCoalAccount.report",_dom);
		}	
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;   
	
	}
} 